package com.aaa.controller;

import com.aaa.service.S_NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/news/")
public class S_NewsController {
    @Autowired
    private S_NewsService service;

    /** 定向页面
     * @return
     */
   @RequestMapping("news")
    public  String toNews(){
        return "publicity/news";
    }

    /** 查询新闻
     * @param map
     * @return
     */
    @RequestMapping("selNews")
    @ResponseBody
    public Object selNews(@RequestBody(required = false) Map map){
        List<Map> data=service.selNews(map);
        Integer total=service.getCount(map);
        List<Map> list=service.selName();
        Map zmap=new HashMap();
        zmap.put("data",data);
        zmap.put("total",total);
        zmap.put("options",list);
        return zmap;
    }
    @RequestMapping("title")
    @ResponseBody
    public Object toTitle(){
        //推荐阅读
        List<Map> titleList = service.selectTitle();
        //地方动态
        List<Map> titleListdf = service.selectTitledf();
        //志愿服务
        List<Map> titleListzy = service.selectTitlezy();

        Map map = new HashMap();
        map.put("titleList",titleList);
        map.put("titleListdf", titleListdf);
        map.put("titleListzy", titleListzy);
        return map;
    }


    /** 添加新闻
     * @param map
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public  Integer add(@RequestBody Map map){
       int row=service.addNews(map);
       return  row;
    }

    /** 修改新闻
     * @param map
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public  Integer update(@RequestBody Map map){
        int row=service.updateNews(map);
        return  row;
    }

    /** 删除新闻
     * @param id
     * @return
     */
    @RequestMapping("del/{id}")
    @ResponseBody
    public  Integer del(@PathVariable Integer id){
        int row=service.delNews(id);
        return  row;
    }

    /** 动态获取下拉列表
     * @return
     */
    @RequestMapping("selname")
    @ResponseBody
    public Object name(){
       List<Map> list=service.selName();
       Map map=new HashMap();
        map.put("options",list);
        System.out.println(map);
       return map;
    }

    /** 提交审核事件
     * @param id
     * @return
     */
    @RequestMapping("sub/{id}")
    @ResponseBody
    public Integer sub(@PathVariable Integer id){
       int row=service.subCheck(id);
       return row;
    }
}
